package com.crm.api.controller;

import com.crm.api.common.Result;
import com.crm.api.service.DashboardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 仪表板控制器
 */
@Slf4j
@RestController
@RequestMapping("/dashboard")
public class DashboardController {

    @Autowired
    private DashboardService dashboardService;

    /**
     * 获取首页统计数据
     */
    @GetMapping("/stats")
    public Result<Map<String, Object>> getDashboardStats() {
        log.info("获取首页统计数据");
        Map<String, Object> stats = dashboardService.getDashboardStats();
        return Result.success(stats);
    }

    /**
     * 获取最近新增客户
     */
    @GetMapping("/recent-customers")
    public Result<Map<String, Object>> getRecentCustomers(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "5") Integer pageSize) {
        log.info("获取最近新增客户: page={}, pageSize={}", page, pageSize);
        Map<String, Object> result = dashboardService.getRecentCustomers(page, pageSize);
        return Result.success(result);
    }

    /**
     * 获取待处理工单
     */
    @GetMapping("/pending-orders")
    public Result<Map<String, Object>> getPendingOrders(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "5") Integer pageSize) {
        log.info("获取待处理工单: page={}, pageSize={}", page, pageSize);
        Map<String, Object> result = dashboardService.getPendingOrders(page, pageSize);
        return Result.success(result);
    }
}